﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Platform : MonoBehaviour
{
    public AudioSource m_Ding;
    public bool outFlagR = false;
    public bool outFlagL = false;
    public Player m_Player;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
       
        var boundsR = GetComponent<Renderer>().bounds;
        var boundsSizeR = boundsR.size.x;
        RaycastHit2D hitR = Physics2D.Raycast(transform.position + new Vector3(boundsR.size.x/2+0.01f,0), Vector2.right);
        if (hitR.collider != null && hitR.distance <= 0.001)
        {
            outFlagR = true;
        }
        else
        {
            outFlagR = false;
        }
        var boundsL = GetComponent<Renderer>().bounds;
        var boundsSizeL = boundsL.size.x;
        RaycastHit2D hitL = Physics2D.Raycast(transform.position - new Vector3(boundsL.size.x/2+0.01f, 0), Vector2.left);
        if (hitL.collider != null && hitL.distance <= 0.001)
        {
            outFlagL = true;
        }
        else
        {
            outFlagL = false;
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        //if(Input.GetKeyDown(KeyCode.Space);
        Ball ball = collision.GetComponent<Ball>();
        if(ball.transform.position.y != 0)
        {
            ball.MoveDir.y *= -1;
        }

        if (m_Ding)
            m_Ding.Play();
    }
}
